/* TCSS 590A - Cybernetics and Systems
 * Group Project - Modeling
 * By Barry Jones, Naren Meadem, Michael Pitts, Yuan Tao
 * Fall 2012, University of Washington, Tacoma
 */
package output;

import java.util.Collection;


/**
 * This contains a collection of OutPut Sources and updates all of them when any
 * output is generated.
 * @author Michael Pitts
 * @version Nov 8, 2012
 */
public class OutPutCollection extends OutPutDelineated
{	
	/** Stores the outputs that will be used. */
	private final OutPut[] my_outputs;
	
	/**
	 * Generates a new OutPutCollection, which will send each indicated output to 
	 * each OutPut object stored in the collection.
	 * @param the_new_line does not matter, as each OutPut in the collection will
	 * have its own new line string.
	 * @param the_delineator does not matter, as each OutPut in the collection will
	 * have its own delineator string.
	 * @param the_outputs are the outputs in the collection.
	 */
	private OutPutCollection(final String the_new_line, final String the_delineator,
			final OutPut[] the_outputs)
	{
		super(the_new_line, the_delineator);
		my_outputs = the_outputs.clone();
	}
	
	/**
	 * Generates an OutPutCollection which will contain all the OutPut objects
	 * in the indicated collection.
	 * @param the_outputs the Collection of OutPut objects to encapsulate.
	 */
	public OutPutCollection(final Collection<OutPut> the_outputs)
	{
		this(the_outputs.toArray(new OutPut[the_outputs.size()]));
	}
	
	/**
	 * Generates an OutPutCollection which will contain all the OutPut objects
	 * in the indicated array.
	 * @param the_outputs are the OutPut objects to encapsulate.
	 */
	public OutPutCollection(final OutPut[] the_outputs)
	{
		this(null, null, the_outputs);
	}

	@Override public void out(final String the_data)
	{
		for (int i = 0; i < my_outputs.length; i++)	my_outputs[i].out(the_data);
	}

	@Override public void out(final long the_data)
	{
		for (int i = 0; i < my_outputs.length; i++)	my_outputs[i].out(the_data);
	}

	@Override public void out(final double the_data)
	{
		for (int i = 0; i < my_outputs.length; i++)	my_outputs[i].out(the_data);
	}

	@Override public void close()
	{
		for (int i = 0; i < my_outputs.length; i++)	my_outputs[i].close();
	}
	
	@Override public void newLine()
	{
		for (int i = 0; i < my_outputs.length; i++)	my_outputs[i].newLine();
	}
	
	@Override public void delineate()
	{
		for (int i = 0; i < my_outputs.length; i++)	my_outputs[i].delineate();
	}
}
